/*------------------------------------------------------------------------------
--                                                                            --
--       This software is confidential and proprietary and may be used        --
--        only as expressly authorized by a licensing agreement from          --
--                                                                            --
--                            Hantro Products Oy.                             --
--                                                                            --
--      In the event of publication, the following notice is applicable:      --
--                                                                            --
--                   (C) COPYRIGHT 2007 HANTRO PRODUCTS OY                    --
--                            ALL RIGHTS RESERVED                             --
--                                                                            --
--          The entire notice above must be reproduced on all copies.         --
--                                                                            --
--------------------------------------------------------------------------------
--
--  Abstract : Header for decoder HW registers access module
--
------------------------------------------------------------------------------*/

#ifndef DECHW_INCLUDED
#define DECHW_INCLUDED

/*------------------------------------------------------------------------------
    1. Include headers
------------------------------------------------------------------------------*/

#include "basetype.h"
#include "hidwldrv.h"

/*------------------------------------------------------------------------------
    2. Module defines
------------------------------------------------------------------------------*/
#ifdef __cplusplus
    extern "C"
    {
#endif


typedef struct
{
    PUCHAR  RegBase;   // virtual base address for HW registers
    u32     RegSize;   // size of HW registers mapping
    HANDLE  Mutex;     // mutex lock among users of dechw
    HANDLE  DevFile;	//device file handle of DWL
} DecHw_t;

#ifdef DEC_UT
#define DECHW_WRITE_REG32(dh,o,v)   DEBUGMSG( DEC_DEBUG, (TEXT("offset:%#x, value:%#x\r\n"), (o), (v)))
#define DECHW_READ_REG32(dh,o )     (o)
#else
#define DECHW_REG32(dh,o)           (*(volatile unsigned long*)((dh)->RegBase + (o)))
#define DECHW_WRITE_REG32(dh,o,v)   do { DECHW_REG32(dh,o) = (v); } while (0)
#define DECHW_READ_REG32(dh,o )     DECHW_REG32(dh,o)
#endif


#define DECHW_LOCK(dh,to)    ( WaitForSingleObject((dh)->Mutex, (to))==WAIT_OBJECT_0 )
#define DECHW_UNLOCK(dh)     ReleaseMutex( (dh)->Mutex )

/*------------------------------------------------------------------------------
    3. Function prototypes
------------------------------------------------------------------------------*/

DecHw_t* DecHw_Init    ( void );
void     DecHw_Release ( DecHw_t* dechw );
void     DecHw_Reset   ( DecHw_t* dechw );
void     DecHw_WriteReg( DecHw_t* dechw, u32 offset, u32 val );
u32      DecHw_ReadReg ( DecHw_t* dechw, u32 offset );

#ifdef __cplusplus
}
#endif


#endif // DECHW_INCLUDED
